package com.wef.modules.sys.entity;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wef.common.utils.PageUtils;
import com.wef.common.utils.Query;
import com.wef.common.utils.R;
import com.wef.modules.sys.service.TrProductService;




/**
 * 产品信息表
 * 
 * @author xxx
 * @email xxx
 * @date 2017-12-27 17:45:14
 */
@RestController
@RequestMapping("trproduct")
public class TrProductController {
	@Autowired
	private TrProductService trProductService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("trproduct:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TrProductEntity> trProductList = trProductService.queryList(query);
		int total = trProductService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(trProductList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{trProductId}")
	@RequiresPermissions("trproduct:info")
	public R info(@PathVariable("trProductId") Long trProductId){
		TrProductEntity trProduct = trProductService.queryObject(trProductId);
		
		return R.ok().put("trProduct", trProduct);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("trproduct:save")
	public R save(@RequestBody TrProductEntity trProduct){
		trProductService.save(trProduct);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("trproduct:update")
	public R update(@RequestBody TrProductEntity trProduct){
		trProductService.update(trProduct);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("trproduct:delete")
	public R delete(@RequestBody Long[] trProductIds){
		trProductService.deleteBatch(trProductIds);
		
		return R.ok();
	}
	
}
